#include "ReceiveControlPointListCmd.h"

ReceiveControlPointListCmd::ReceiveControlPointListCmd(QObject *parent) :
    BaseCmd(parent)
{
    this->m_protocolType = ProtocolType::ZigbeeControlProtocol;
    this->m_functionCode = FunctionCode;
}

Package ReceiveControlPointListCmd::toPackage()
{
    Package package;
    return package;
}

void ReceiveControlPointListCmd::unPackage(Package package)
{
    QByteArray body = package.body();
    quint16 index = 0;

    quint8 size = body.mid(index,1).toHex().toUInt(0,16);
    index += 1;

    for(int i=0; i<size; i++)
    {
        quint16 address = (quint16)body.at(index+1) <<8 | (quint8)body.at(index);
        index += 2;

        quint16 value = (quint16)body.at(index+1) <<8 | (quint8)body.at(index);
        index += 2;

        ControlPointStruct point;
        point.setAddress(address);
        point.setValue(value);
        m_controlPointList.append(point);
    }
}
QList<ControlPointStruct> ReceiveControlPointListCmd::controlPointList() const
{
    return m_controlPointList;
}

void ReceiveControlPointListCmd::setControlPointList(const QList<ControlPointStruct> &controlPointList)
{
    m_controlPointList = controlPointList;
}

